Reference for bindings expressions

Here you can find the reference for the bindings expressions you can add to the bindings of your objects, styles, and state managers. See Using styles and State managers.

You can create bindings after you add the Bindings property to a node. Blue type marks the properties that are controlled by a binding.

When creating bindings, note that:

See Using bindings.

Syntax   Common binding expressions
  # (comments)
() (parentheses)
= (assign)
  Operators
  + (addition)
- (subtraction)
* (multiplication)
/ (division)
  Casting
  Integer
Float
Boolean
String
  Functions
  Absolute value
Animate
Ceil
Clamp
Floor
Linear step
Max
Min
Mix
Modulo
Power
Round
Square root
Step
  Constants
Variables
Property bindings
Alias bindings
Attribute bindings
Color attribute bindings
Transformation attribute bindings

Syntax

# (comments)

Use a hash at the beginning of every line that contains a comment. You can use any sequence of characters in comments.

# This is a comment, so you can describe your binding expressions
# Calculate the value of A
A = (2 + 4) / 3

() (parentheses)

Use parentheses to group and contain expressions and parameters, and control the order of execution.

# Containing expressions: calculate the modulo of two values
MOD(23, 27)

# Grouping expressions: first add 2 and 4, then divide the result by 3,
# and return 2
A = (2 + 4) / 3

# First add FOV property to Render Transformation property attribute Scale X,
# then divide the result of the multiplication by 2
({../Camera/Fov} + {../Box/RenderTransformation}.ScaleX) / 2

= (assign)

Assigns a value to a variable.

Syntax var = value
Parameters
var any valid variable name
value any supported variable value
Examples

# Assigns the value 2.0 to the variable 'A'
A = 2.0

# Assigns the value 4.0 to the variable 'B'
B = 4.0

Operators

+ (addition)

Adds two or more values, or combines strings into one.

Syntax value1 + value2
Parameters
value1 color, int, float, string, vector2D, vector3D, vector4D, or boolean: augend
value2 color, int, float, string, vector2D, vector3D, vector4D, or boolean: addend
Returns the same type as parameters, except if one of parameters is float, it returns float
Examples

A = 2.0
B = 4.0

# Returns 6.0
A + B

- (subtraction)

Subtracts the value of the second parameter from the value of the first parameter. As a negation operator, it returns the result equivalent to multiplying the value by -1.

Syntax value1 - value2
Parameters
value1 color, int, float, string, vector2D, vector3D, vector4D, or boolean: minuend
value2 color, int, float, string, vector2D, vector3D, vector4D, or boolean: subtrahend
Returns the same type as parameters, except if one of parameters is float, it returns float
Examples

A = 2.0
B = 4.0

# Returns -2.0
A - B

* (multiplication)

Multiplies the values of parameters.

Syntax value1 * value2
Parameters
value1 color, int, float, vector2D, vector3D, vector4D, or boolean: multiplicand
value2 color, int, float, vector2D, vector3D, vector4D, or boolean: multiplier

Note that only one of the parameters can be boolean, but not both.

Returns

the same type as parameters, except:

  • If one of parameters is a float, it returns float
  • If one of parameters is boolean, it returns int, or float if at least one parameter is float
Examples

A = 2.0
B = 4.0

# Returns 8.0
A * B

/ (division)

Divides the value of the first parameter by the value of the second parameter.

Syntax value1 / value2
Parameters
value1 color, int, float, vector2D, vector3D, vector4D, or boolean: dividend
value2 color, int, float, vector2D, vector3D, vector4D, or boolean: divisor

Note that only one of the parameters can be boolean, but not both.

Returns

the same type as parameters, except:

  • If one of parameters is a float, it returns float
  • If one of parameters is boolean, it returns int, or float if at least one parameter is float
Examples

A = 2.0
B = 4.0

# Returns 0.5
A / B

Casting

Casts between integer, float, and boolean are implicit and depend on the type of the property that uses the value. Casts to and from string are explicit.

Integer

Converts a value to an integer. Casts between integer, float, and boolean are implicit and depend on the type of the property that uses the value. Casts to and from string are explicit.

Syntax INT(value)
Parameters
value float, boolean, string
Returns int
Examples

# Explicitly converts the string "5" to an integer, adds it to the integer 5,
# and assigns the result to the variable A. Returns integer 10.
A = 5 + INT("5")

# Implicitly converts boolean value True to integer, adds it to the integer 5,
# and assigns the result to the variable A. Returns integer 6.
B = 5 + True

# Explicitly converts float 5.5 to an integer, adds it to the integer and
# assigns the result to the variable C. Returns integer 7.
C = 2 + INT(5.5)

Float

Converts a value to a float. Casts between integer, float, and boolean are implicit and depend on the type of the property that uses the value. Casts to and from string are explicit.

Syntax FLOAT(value)
Parameters
value int, boolean, string
Returns float
Examples

# Converts the string "5" to a float, adds it to the integer 5,
# and assigns the result to the variable A. Returns float 10.000000.
A = 5 + FLOAT("5")

# Implicitly converts boolean value True to float, adds it to the float 5.1,
# and assigns the result to the variable A. Returns float 6.1.
B = 5.1 + True

Boolean

Converts a value to a boolean. Casts between integer, float, and boolean are implicit and depend on the type of the property that uses the value. Casts to and from string are explicit.

Syntax BOOL(value)
Parameters
value int, float, string
Returns bool
Examples

# Converts the string value "True" to a boolean, adds it to the integer 5,
# and assigns the result to the variable A. Returns integer 6.
A = 5 + BOOL("True")

String

Converts a value to a string. Casts between integer, float, and boolean are implicit and depend on the type of the property that uses the value. Casts to and from string are explicit.

Syntax STRING(value)
Parameters
value int, float, boolean
Returns string
Examples

# Converts the integer 5 to a string, concatenates it to the string
# "Five is written as ", and assigns the result to the variable B.
# Returns string "Five is written as 5".
A = "Five is written as " + STRING(5)

# Converts the value of the variable A to a string, concatenates it
# to the string "Number of fingers on two hands is ", and assigns the result
# to the variable B. Returns string "Number of fingers on two hands is 10".
A = 10
C = "Number of fingers on two hands is " + STRING(A)

Functions

Absolute value

Calculates the absolute value of a number or a variable. The absolute value of a number is always positive.

Syntax ABS(value)
Parameters
value color, int, float, vector2D, vector3D, vector4D: number to compute
Returns the same type as parameter
Examples

# Returns 5.2
ABS(-5.2)

Animate

Binds a property value to a piecewise function that you define in an Animation Data item. See Using piecewise functions in bindings.

Animate takes two arguments: the property to which you are binding the Animation Data item, and the resource ID of the Animation Data item where you define the piecewise function you want to use to set the value of the bound property. You have to place the Animation Data item to the resource dictionary where the object containing the binding can access it. See Using local and global resources.

For example, you can use the Animate function to set how quickly a needle in a gauge moves: you can set the needle to move faster from values 0 to 100 than it does for values from 100 to 250.

Syntax Animate(property, "animationDataResourceID")
Parameters
property

path and name of the property you want to use to move along the animation curve instead of time

animationDataResourceID resource ID of the Animation Data item the animation curve of which you want to use to set the value of the bound property
Examples

# Uses the Position property to move along the animation curve
# of the Animation Data item with the resource ID Speed curve.
Animate({@./Position}, "Speed curve")

Ceil

Calculates the closest integer value that is greater than or equal to the value of the parameter.

Syntax CEIL(value)
Parameters
value color, int, float, vector2D, vector3D, vector4D: number to compute
Returns the same type as parameter, except for float parameters it returns int
Examples

# Returns 3.0
CEIL(2.06)

# Returns 16.0
CEIL(15.92)

Clamp

Constrains a value to lie between two values. CLAMP returns the same value as MIN(MAX(value, low), high).

Syntax CLAMP(low, high, value)
Parameters
low int or float: the lower end of the range to constrain the value
high int or float: the higher end of the range to constrain the value
value int or float: the value to constrain
Returns float if any of the parameters is float, otherwise int
Examples

# Returns 1
CLAMP(1, 4, 0.5)

# Returns 4
CLAMP(-3, 8, 4)

Floor

Calculates the closest integer value that is less than or equal to the value of the parameter.

Syntax FLOOR(value)
Parameters
value color, int, float, vector2D, vector3D, vector4D: number to compute
Returns the same type as parameter, except for float parameters it returns int
Examples

# Returns 0
FLOOR(0.8)

# Returns 1
FLOOR(1.5)

# Returns 15
FLOOR(15.92)

Linear step

Performs linear interpolation between two values. LINEARSTEP returns the same value as CLAMP(0, 1 (value - low) / (high - low)).

Syntax LINEARSTEP(low, high, value)
Parameters
low int or float: the lower end of the linear function
high int or float: the higher end of the linear function
value int or float: the value to constrain
Returns

float if one of the parameters is float, otherwise int:

  • 0.0 if value is less than or equals low
  • 1.0 if value is greater than or equals high
  • Otherwise (value - low) / (high - low)
Examples

# Returns 0.0
LINEARSTEP(1, 4, 0.5)

# Returns 0.64 (7/11)
LINEARSTEP(-3, 8, 4)

Max

Determines the larger of the two values and returns the larger value.

Syntax MAX(value1, value2)
Parameters
value1 int, float, vector2D, vector3D, vector4D, or boolean: the first number to compare
value2 int, float, vector2D, vector3D, vector4D, or boolean: the second number to compare

Note that only one of the parameters can be boolean, but not both.

Returns the same type as parameters, float if one of parameters is float, otherwise int
Examples

# Returns 5
MAX(2, 5)

# Returns -2.1
MAX(-10, -2.1)

Min

Determines the smaller of the two values and returns the smaller value.

Syntax MIN(value1, value2)
Parameters
value1 int, float, vector2D, vector3D, vector4D, or boolean: the first number to compare
value2 int, float, vector2D, vector3D, vector4D, or boolean: the second number to compare

Note that only one of the parameters can be boolean, but not both.

Returns the same type as parameters, float if one of parameters is float, otherwise int
Examples

# Returns 2
MIN(2, 5)

# Returns -10
MIN(-10, -2.1)

Mix

Performs a linear interpolation between two values using a value to weight between them. Kanzi computes the result using this function: (end - start) * weight + start.

Syntax MIX(start, end, weight)
Parameters
start int or float: the start of the interpolation range
end int or float: the end of the interpolation range
weight int or float: the value used for interpolation between start and end
Returns float if one of parameters is float, otherwise int
Examples

# Returns 2.5
MIX(1, 4, 0.5)

# Returns 0.5
MIX(-1, -4, -0.5)

Modulo

Calculates the remainder when one number is divided by another. MOD() takes a division as a parameter and returns the remainder.

Syntax MOD(value1, value2)
Parameters
value1 int, float, vector2D, vector3D, vector4D, or boolean: the first number to compare: dividend
value2 int, float, vector2D, vector3D, vector4D, or boolean: the first number to compare: divisor

Note that only one of the parameters can be boolean, but not both.

Returns the same type as parameters, float if one of parameters is float, otherwise int
Examples

# Returns 2.1
MOD(12.1, 5)

# Returns 23
MOD(23, 27)

Power

Calculates exponential expressions. It is an efficient way for multiplying numbers by themselves.

Syntax POW(n, e)
Parameters
n int, float, color, vector2D, vector3D, vector4D: base of the exponential expression
e int, float, or boolean: power by which to raise the base
Returns the same type as parameter n, except for int it returns float
Examples

# Is equivalent to 2*2*2*2*2 and returns 32
POW(2, 5)

Round

Calculates the closest integer.

Syntax ROUND(value)
Parameters
value color, int, float, vector2D, vector3D, vector4D: number to compute
Returns the same type as parameter, except for float it returns int
Examples

# Returns 1.0
ROUND(0.8)

# Returns 2.0
ROUND(1.5)

# Returns 0.0
ROUND(0.1)

Square root

Calculates the square root of a number. The square root value of a number is always positive.

Syntax SQRT(n)
Parameters
n int, float, color, vector2D, vector3D, vector4D: number to compute
Returns the same type as parameter, except for int it returns float
Examples

# Returns 5.0
SQRT(25)

Step

Compares a value to a threshold.

Syntax STEP(threshold, value)
Parameters
threshold int, float, color, vector2D, vector3D, vector4D: threshold to compare against
value int, float, color, vector2D, vector3D, vector4D: number to compute: the value to compare against the threshold
Returns float, 0.0 if the value is lower than the threshold, 1.0 if the value equals or is greater than the threshold
Examples

# Returns 1.0
STEP(2, 5)

# Returns 0.0
STEP(0.0, -0.1)

# Returns 1.0
STEP(1.0, 1.0)

Common binding expressions

Constants

To bind a property value to a constant, enter just the constant.

# Binds the value of the selected property to 10.
10

Variables

In binding expressions you can use variables.

# Assigns the value 1 to the variable 'A', and binds the value of
# the variable to the selected property.
A = 1

# Same as above, but using an alternative syntax.
A = (1)

Property bindings

To bind a property to another property, enter in curly braces the @ sign followed by the relative path to the object, followed by a forward slash and source property name.

When you use the @ sign before the path, Kanzi Studio updates the binding expression whenever the location between the source and the target object in the scene graph changes. Note that with the @ sign you can create bindings only within the same prefab, not between prefabs.

You can drag property names from the Properties to the Binding Argument Editor.

You can use the operators and parentheses with property values and property attribute values.

Syntax {[path]/[property]}
Parameters
[path] relative path to object
[property] name of the property
Examples

# Binds to property Layout Width of the current object.
{@./LayoutWidth}

# Binds to the property FOV of the Camera object.
{@../Camera/Fov}

# Same as above, but Kanzi Studio does not track the location of the target object.
{../Camera/Fov}

# Binds to the property Vertical Margin of the Box object
{@../Box/LayoutVerticalMargin}

# Multiplies the FOV property with the Layout Transformation property attribute Scale X.
{@../Camera/Fov} * {../Box/LayoutTransformation}.ScaleX

Alias bindings

To bind a property to an alias, enter in curly braces the # sign followed by the alias name, followed by a forward slash and property name of the alias' target. See Using aliases.

Syntax {#[aliasName]/[property]}
Parameters
[aliasName] name of the alias
[property] name of the property
Examples

# Binds to the Layout Width property of the target object of the alias named Sphere.
{#Sphere/LayoutWidth}

# Multiplies the FOV property of the target object of the alias named MainCamera
# with the Render Transformation property attribute Scale X.
{#MainCamera/Fov} * {../Box/RenderTransformation}.ScaleX

Attribute bindings

To bind a property to object's property common attribute, enter in curly braces the relative path to the object, followed by a forward slash and property name, followed by a period and attribute name. For property attributes that are not common, instead of the attribute name use VectorN, where N is X, Y, Z, or W denoting the order in which the property is listed in the Properties. You can use the operators and parentheses with property values and property attribute values.

When you want to bind a property to an attribute use the following attributes.

Description Attribute name Attribute alternative names
Color property red color channel value ColorR Color_R, R
Color property green color channel value ColorG Color_G, G
Color property blue color channel value ColorB Color_B, B
Color property alpha channel value ColorA Color_A, A
Value of the object rotation around the X axis RotationX Rotation_X
Value of the object rotation around the Y axis RotationY Rotation_Y
Value of the object rotation around the Z axis RotationZ Rotation_Z
Value of the object scale along the X axis ScaleX Scale_X
Value of the object scale along the Y axis ScaleY Scale_Y
Value of the object scale along the Z axis ScaleZ Scale_Z
Value of the object location along the X axis TranslationX Translation_X, X
Value of the object location along the Y axis TranslationY Translation_Y, Y
Value of the object location along the Z axis TranslationZ Translation_Z, Z
The first attribute of a property VectorX Vector_X
The second attribute of a property VectorY Vector_Y
The third attribute of a property VectorZ Vector_Z
The fourth attribute of a property VectorW Vector_W

 

Syntax {[path]/[property]}.[attribute]
Parameters
[path] relative path to object
[property] name of the property
[attribute] name of the attribute
Examples

# Binds to the attribute Scale X (value of the Scale X attribute)
# of the Box node's Layout Transformation property.
{../Box/LayoutTransformation}.ScaleX

# Binds to the attribute Color R (value of the red color channel)
# of the Point Light node's Point Light Color property.
{../Point Light/PointLightColor}.ColorR

# Light objects have an attenuation property that has three attributes:
# Constant, Linear, and Quadratic.
# For example, for the Point Light:
# To bind to the first attribute (Constant)
{../Light/PointLightAttenuation}.VectorX

# To bind to the second attribute (Linear)
{../Light/PointLightAttenuation}.VectorY

# To bind to the third attribute (Quadratic)
{../Light/PointLightAttenuation}.VectorZ

# Multiply property FOV with Render Transformation property attribute Scale X.
{../Camera/Fov} * {../Box/RenderTransformation}.ScaleX

Color attribute bindings

Color4()binds color attributes. Color4() takes four arguments: the first specifies the value for the red color channel, the second specifies the value for the green color channel, the third specifies the value for the blue color channel, and the fourth specifies the value for the alpha channel. Color values are mapped to the range 0..1.

Syntax Color4(r, g, b, a)
Parameters
r

0...1 range: red color channel value

g

0...1 range: green color channel value

b

0...1 range: blue color channel value

a

0...1 range: alpha channel value

Examples

# Sets the color to white and opaque.
Color4(1, 1, 1, 1)

# Same as above, but with alternative syntax.
Color(1, 1, 1, 1)

# Sets the color to red with 50% transparency.
Color4(1, 0, 0, 0.5)

# Invalid expression, one argument is missing.
Color4(0.1, 1, 0.4)

# Use variables as attributes of the Color4() to assign the
# attribute values of the whole Color property.
#
# Assigns custom properties Red, Green, and Blue to variables
# you use to control the color of an object.
red = {@./Red}
green = {@./Green}
blue = {@./Blue}
color = Color4(0, 0, 0, 1)
# Assigns the red, green, and blue variables to each color channel attribute.
color.ColorR = red
color.ColorG = green
color.ColorB = blue
color

Transformation attribute bindings

MatrixSRT() binds transformation attributes. MatrixSRT() takes nine arguments: the first three arguments specify the scale transformation, the second three arguments specify the rotation transformation, and the last three arguments specify the translation transformation.

Syntax MatrixSRT(ScaleX, ScaleY, ScaleZ, RotationX, RotationY, RotationZ, TranslationX, TranslationY, TranslationZ)
Parameters
ScaleX int, or float: scale of the object on the x-axis
ScaleY int, or float: scale of the object on the y-axis
ScaleZ int, or float: scale of the object on the z-axis
RotationX int, or float: rotation of the object on the x-axis in degrees
RotationY int, or float: rotation of the object on the y-axis in degrees
RotationZ int, or float: rotation of the object on the z-axis in degrees
TranslationX int, or float: translation of the object on the x-axis
TranslationY int, or float: translation of the object on the y-axis
TranslationZ int, or float: translation of the object on the z-axis
Examples

# Scales the object on the x, y, and z axes to 1 unit,
# rotates it around the x axis by 30 degrees
# and moves it on the z axis by 2 units.
MatrixSRT(1, 1, 1, 30, 0, 0, 0, 0, 2)

# Use variables as attributes of the MatrixSRT() to assign the
# attribute values of the whole Render Transformation property.

# Assigns custom property Rotation to a variable you use to control
# the rotation of an object.
rotate = {@./Rotation}
position = MatrixSRT(1, 1, 1, 0, 0, 0, 0, 0, 0)

# Assigns the rotation variable to each rotation attribute.
position.RotationX = rotate
position.RotationY = rotate
position.RotationZ = rotate
position

See also

Using bindings

Using aliases